import { http, Result, ResultBoolean, ResultPageInfo, ResultString } from "@/utils/http";

/** 系统配置管理API */
export const configApi = {
	/** 获取配置分页列表 */
	getPostPageList: (data: SysConfigQuery) =>
		http.request<ResultPageInfo<SysConfig>>("post", "/system/config/list", { data }),
	getPageList: (data: SysConfigQuery) =>
		http.request<ResultPageInfo<SysConfig>>("get", "/system/config/list", { data }),

	/** 获取配置详情 */
	getDetail: (id: string) =>
		http.request<Result<SysConfig>>("get", `/system/config/${id}`),

	/** 新增配置 */
	create: (data: SysConfig) =>
		http.request<ResultBoolean>("post", "/system/config", { data }),

	/** 修改配置 */
	update: (data: SysConfig) =>
		http.request<ResultBoolean>("put", "/system/config", { data }),

	/** 删除配置 */
	delete: (ids: string[]) =>
		http.request<ResultBoolean>("delete", `/system/config/${ids.join(",")}`),

	/** 批量删除配置 */
	batchDelete: (ids: string[]) =>
		http.request<ResultBoolean>("delete", "/system/config/batch", { data: ids }),

	/** 通过键名获取配置值 */
	putByKey: (configKey: string, configValue: string) =>
		http.request<ResultString>("put", `/system/config/configKey/${configKey}`, { data: { "configKey": configKey, "configValue": configValue } }),

	/** 通过键名获取配置值 */
	putConfigByKey: (data: object) =>
		http.request<ResultString>("get", `/system/config/configKey`, { data }),

	/** 刷新配置缓存 */
	refreshCache: () =>
		http.request<ResultBoolean>("delete", "/system/config/refreshCache")
};

/** 系统配置实体 */
export interface SysConfig {
	id?: string;
	configName: string;
	configKey: string;
	configValue: string;
	configType: number;
	isBuiltin: number;
	status: number;
	remark?: string;
}

/** 系统配置分页查询参数 */
export interface SysConfigQuery {
	pageNum?: number;
	pageSize?: number;
	configName?: string;
	configKey?: string;
	configType?: number;
	status?: number;
}